home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / DBCOMPRS.C < prev    next >
Text File  |  1985-10-26  |  3KB  |  120 lines

  1. /*
  2.  * Program to read a dBASE program file and produce a copy of it
  3.  * from which the comment lines have been discarded and in which
  4.  * leading spaces before program lines have also been discarded.
  5.  */
  6. #include "stdio.h"
  7. #define CR 0xd
  8. #define LF 0xa
  9. #define TB 0x9
  10. #define SP 0x20
  11. #define TRUE 1
  12. #define FALSE 0
  13. main(argc,argv)
  14.     int argc;
  15.     char *argv[];
  16.     {
  17.     char buffer[256];
  18.     int  c,
  19.      comment,
  20.      buffposn,
  21.      eofinp,
  22.      outfile,
  23.      infile;
  24.     if ((argc == 1) || (argv[1][0] == '?'))
  25.     {
  26.     puts("\n");
  27.     puts("Syntax: DBCOMPRS <infile> <outfile>\n");
  28.     puts("where   infile  is the filespec for the input data\n");
  29.     puts("        outfile is the filespec for the output data\n");
  30.     puts("\n");
  31.     puts("The input file is assumed to be a dBASE .PRG file.\n");
  32.     puts("\n");
  33.     puts("The output file is merely a copy of the input file with the\n");
  34.     puts("comment lines and leading spaces before code lines stripped\n");
  35.     puts("from it .\n");
  36.     puts("\n");
  37.     exit(0);
  38.     }
  39.     if (argv[1][0] == '#')
  40.     {
  41.     puts("\n");
  42.     puts("PROGRAM: DBCOMPRS\n");
  43.     puts("Author : Peter Townsend\n");
  44.     puts("Date   : 25Oct85\n");
  45.     puts("Version: 1.0\n");
  46.     exit(0);
  47.     }
  48.     if ((infile = open(argv[1],0)) == -1)
  49.     {
  50.     printf("\nCannot open input file %s\n",argv[1]);
  51.     exit(1);
  52.     }
  53.     if (argc == 2)
  54.     {
  55.     printf("\nMissing Output Filename\n");
  56.     exit(1);
  57.     }
  58.     if (strcmp(argv[1],argv[2]) == 0)
  59.     {
  60.     printf("\nInput filename and output filename cannot be the same.\n");
  61.     exit(1);
  62.     }
  63.     if ((outfile = open(argv[2],1)) == -1)
  64.     {
  65.     if ((outfile = creat(argv[2])) == -1)
  66.         {
  67.         printf("\nCannot create output file %s\n",argv[2]);
  68.         exit(1);
  69.         }
  70.     }
  71.     eofinp = FALSE;
  72.     while (!eofinp)
  73.     {
  74.     /*
  75.      * Read a line into the buffer
  76.      */
  77.     buffposn = 0;
  78.     c = fgetc(infile);
  79.     eofinp = (c == EOF);
  80.     while ((c != LF) && (!eofinp))
  81.         {
  82.         buffer[buffposn++] = c;
  83.         c = fgetc(infile);
  84.         eofinp = (c == EOF);
  85.         }
  86.     if (c == LF)
  87.         {
  88.         buffer[buffposn++] = c;
  89.         }
  90.     /*
  91.      * Make the buffer a string by terminating it with a null
  92.      */
  93.     buffer[buffposn] = '\0';
  94.     /*
  95.      * Step along the string until a non-blank or -tab is
  96.      * encountered or until end of string
  97.      */
  98.     buffposn = 0;
  99.     c = buffer[buffposn];
  100.     while ((c == SP) || (c == TB))
  101.         {
  102.         c = buffer[++buffposn];
  103.         }
  104.     comment = (c == '*');
  105.     /*
  106.      * If the line isn't a comment, output it
  107.      */
  108.     if (!comment)
  109.         {
  110.         while(buffer[buffposn] != '\0')
  111.         {
  112.         putc(buffer[buffposn++],outfile);
  113.         }
  114.         }
  115.     }
  116.     fclose(infile);
  117.     fclose(outfile);
  118.     exit(0);
  119.     }
  120.